<%@ page language="java" import="org.json.*,java.sql.*,com.microsoft.sqlserver.jdbc.*,java.io.*,web.rec.*" 
contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"  %>

<% 
	Connection conn = ResourceTool.getConnection();
%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="script/jquery-1.6.3.min.js"></script>
<script type="text/javascript" src="script/form_script.js"></script>
</head>
<body>
          <%
			try {
			// Create the prepared statement and use it to
			// INSERT the student attrs INTO the Student table.
			Statement stmt = conn.createStatement();
			String action = request.getParameter("action");
			%>
			<table>
			<tr>
				<th>class id</th>
				<th>title</th>
				<th>course num</th>
				<th>year</th>
				<th>quarter</th>
				<th>units</th>
				<th>section_id</th>
			</tr>
			<%
			String student_id = request.getParameter("student_id");
			if (action != null && action.equals("submit"))
			{
				String sql = "select * from Class, Section, StudentTakingSection where "
				   	       + "Class.class_id = Section.class_id and "
						   + "Section.section_id = StudentTakingSection.section_id and "
						   + "StudentTakingSection.student_id = '"+ student_id + "' and "
						   + "year = 2012 and season = 'WINTER'";
				System.out.println(sql);
				ResultSet rs = stmt.executeQuery(sql);

				while(rs.next())
				{
			%>
			<tr>
				<td><%= rs.getString("class_id") %></td>
				<td><%= rs.getString("title") %></td>
				<td><%= rs.getString("course_num") %></td>
				<td><%= rs.getInt("year") %></td>
				<td><%= rs.getString("season") %></td>
				<td><%= rs.getInt("units") %></td>
				<td><%= rs.getString("section_id") %></td>
			</tr>
			<%
				}
			}
			} catch (SQLException sqle) {
				out.println(sqle.getMessage());
			} catch (Exception e) {
				out.println(e.getMessage());
			}    
            %>
      </table>
</body>
</html>